package com.rocketmq.listener;

import com.alibaba.fastjson.JSON;
import com.rocketmq.domian.MsgModel;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

/**
 * @Author 派大星
 * @Description TODO
 * @Date 2025/7/31 16:45
 */
@Component
@RocketMQMessageListener(topic = "bootOrderlyTopic",
        consumerGroup = "boot-orderly-consumer-group",
        consumeMode = ConsumeMode.ORDERLY, // 属性消费模式 单行程的
        maxReconsumeTimes = 5 // 消费重试的次数
)
public class BOrderlyMsgListener implements RocketMQListener<MessageExt> {

    @Override
    public void onMessage(MessageExt messageExt) {
        MsgModel msg = JSON.parseObject(new String(messageExt.getBody()), MsgModel.class);
        System.out.println("接收到消息：" + msg);
    }
}
